#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define mp(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
int a[210][210];
ll dp[210][210];

int main(){
	freopen("find.in","r",stdin);
	freopen("find.out","w",stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=n;i>=1;i--){
		for(int j=m;j>=1;j--){
			if(a[i][j]==-1){
				dp[i][j]=0;
			}
			else if(a[i+1][j]==-1&&a[i][j+1]==-1){
				dp[i][j]=-1;
			}
			else if(a[i+1][j]==-1&&a[i][j+1]!=-1){
				dp[i][j]=a[i][j]+dp[i][j+1];
			}
			else if(a[i+1][j]!=-1&&a[i][j+1]==-1){
				dp[i][j]=a[i][j]+dp[i+1][j];
			}else{
				dp[i][j]=max(dp[i+1][j]+a[i][j],dp[i][j+1]+a[i][j]);
			}
		}
	}
	cout<<dp[1][1]<<endl;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

